package com.oneday.nuo.base.security.user;


import com.anji.captcha.model.vo.CaptchaVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * 用户Bean
 * @Author: liushuai
 * @Date: 2021/2/9 21:48
 * @param : * @param null
 * @return :
 **/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class NuoUser implements UserDetails, Authentication, Serializable {
    /**
     * 主键主键
     */
    @NotNull(message = "{id.require}")
    @ApiModelProperty(value = "主键主键")
    private Long id;
    /**
     * 真实姓名
     */
    @NotNull(message = "真实姓名不能为空")
    @ApiModelProperty(value = "真实姓名")
    private String realName;

    /**
     * 用户编号
     */
    @ApiModelProperty(value = "用户编号")
    private String userCode;

    /**
     * 年龄
     */
    @ApiModelProperty(value = "年龄")
    private Integer age;
    /**
     * 电话号码
     */
    @ApiModelProperty(value = "电话号码")
    private Long phone;
    /**
     * 邮箱
     */
    @ApiModelProperty(value = "邮箱")
    private String mail;
    /**
     * 性别(男0/女1)
     */
    @ApiModelProperty(value = "性别(男0/女1)")
    private Integer sex;

    /**
     * 部门id
     */
    @NotNull(message = "部门id不能为空")
    @ApiModelProperty(value = "部门id")
    private String deptId;
    /**
     * 创建人
     */
    @NotNull(message = "创建人不能为空")
    @ApiModelProperty(value = "创建人")
    private String createUser;
    /**
     * 创建时间
     */
    @NotNull(message = "创建时间不能为空")
    @ApiModelProperty(value = "创建时间")
    private Date createDate;
    /**
     * 修改人
     */
    @NotNull(message = "修改人不能为空")
    @ApiModelProperty(value = "修改人")
    private String updateUser;
    /**
     * 修改时间
     */
    @NotNull(message = "修改时间不能为空")
    @ApiModelProperty(value = "修改时间")
    private Date updateDate;
    @ApiModelProperty("验证码后端校验信息")
    private CaptchaVO captchaVO;
    private String token;
    private String userName;
    private String password;
    private List<? extends GrantedAuthority> authorities;
    // 账号是否未过期
    private Boolean accountNonExpired;
    // 账号是否未锁定
    private Boolean accountNonLocked;
    // 账号凭证是否未过期
    private Boolean  credentialsNonExpired;
    // 账户是否可用
    private Boolean enabled;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {

        return authorities;
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getDetails() {
        return password;
    }

    @Override
    public Object getPrincipal() {
        return userName;
    }

    @Override
    public boolean isAuthenticated() {
        return false;
    }

    @Override
    public void setAuthenticated(boolean b) throws IllegalArgumentException {

    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.userName;
    }
    /**
     *
     * 账号是否生效
     * 生效为:true
     * 不生效为:fals
     * @Author: liushuai
     * @Date: 2021/2/9 21:27
     * @param : * @param
     * @return :boolean
     **/
    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }
    /**
     * 账户是否未锁定
     * 锁定:false
     * 未锁定:true
     * @Author: liushuai
     * @Date: 2021/2/9 21:37
     * @param : * @param
     * @return :boolean
     **/
    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }
    /**
     *  账号凭证是否未过期
     *  过期: false
     *  未过期: true
     * @Author: liushuai
     * @Date: 2021/2/9 21:43
     * @param : * @param
     * @return :boolean
     **/
    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }
    /**
     * 账号是否可用
     * @Author: liushuai
     * @Date: 2021/2/9 21:46
     * @param : * @param
     * @return :boolean
     **/
    @Override
    public boolean isEnabled() {
        return enabled;
    }

    @Override
    public String getName() {
        return null;
    }
}
